﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EntityBinder.Interface;

namespace EntityBinder
{
	public static class EntityWriterFactory
	{
		#region GetWriter factory

		public static IEntityWriter GetWriter(EntityBinderFormat _format)
		{
			if(_format == EntityBinderFormat.XML)
			{
				return new Xml.XmlWriter();
			}
			else if(_format == EntityBinderFormat.JSON)
			{
				return new Json.JsonWriter();
			}

			throw new EntityBinderException("EntityWriterFactory", "GetWriter", "Can not process format " + _format);
		}

		public static IEntityWriter GetWriter(EntityBinderFormat _format, IEntityElement _rule)
		{
			if (_format == EntityBinderFormat.XML)
			{
				return new Xml.XmlWriter(_rule);
			}
			else if(_format == EntityBinderFormat.JSON)
			{
				return new Json.JsonWriter(_rule);
			}

			throw new EntityBinderException("EntityWriterFactory", "GetWriter", "Can not process format " + _format);
		}

		public static IEntityWriter GetWriter(EntityBinderFormat _format, Type _writableType)
		{
			return GetWriter(_format, EntityRulesFactory.GetRules(_writableType));
		}

		public static IEntityWriter GetWriter<T>(EntityBinderFormat _format)
		{
			return GetWriter(_format, EntityRulesFactory.GetRules<T>());
		}

		#endregion
	}
}
